<?
class App_Module_Media_Layout extends Mozg_Layout
{
    protected function DefaultTmp ()
    {
       
    }

    protected function JSTmp ()
    {
        $this->SetPublicStaticHeaders();
        Mozg::Response('http')->SetHeader('Content-Type', 'application/x-javascript; charset=UTF-8');
    }

    protected function CSSTmp ()
    {
        $this->SetPublicStaticHeaders();
        Mozg::Response('http')->SetHeader('Content-Type', 'text/css; charset=UTF-8');
    }

    protected function HTMLTmp ()
    {
        $this->SetPublicStaticHeaders();
        Mozg::Response('http')->SetHeader('Content-Type', 'text/html; charset=UTF-8');
    }
    
    protected function EmptyTmp ()
    {
        Mozg::Response('http')->SetHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0', true);
        Mozg::Response('http')->SetHeader('Pragma', 'no-cache', true);
        Mozg::Response('http')->SetHeader('Expires', gmdate('D, d M Y H:i:s', time() - 1) . 'GMT', true);
        Mozg::Response('http')->SetHeader('Content-Type', 'text/html; charset=UTF-8');

        $t = $this->GetTpl('Base');
        $t->metaTitle = implode('', Mozg::SubAction()->Get('Meta Title'));
        $t->content = Mozg::Response('http')->GetBody();
        Mozg::Response('http')->SetBody($t->EmptyTmp());
    }
    
    protected function ImageTmp ()
    {
        list($imageInfo) = Mozg::SubAction()->Get('imageInfo');
        
        $this->SetPublicStaticHeaders();
        Mozg::Response('http')->SetHeader('Content-Length', $imageInfo['filesize']);
        Mozg::Response('http')->SetHeader('Content-Type', $imageInfo['mime']);
    }

    protected function SetPublicStaticHeaders()
    {
        $maxAgeSec = 2593000;
        Mozg::Response('http')->SetHeader('Cache-Control', 'max-age=' .$maxAgeSec. ', public', true);
        Mozg::Response('http')->SetHeader('Pragma', '', true);
        Mozg::Response('http')->SetHeader('Set-Cookie', '', true);
        Mozg::Response('http')->SetHeader('Accept-Ranges', 'bytes', true);
        Mozg::Response('http')->SetHeader('Expires', gmdate('D, d M Y H:i:s', time() + $maxAgeSec) . ' GMT', true);
        Mozg::Response('http')->SetHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT', true);
    }
}